//
//  BDPayRedEnvelopeTableViewCell.m
//  BadBoy
//
//  Created by wen on 2017/7/10.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDPayRedEnvelopeTableViewCell.h"

@interface BDPayRedEnvelopeTableViewCell ()

@property (nonatomic, strong) UILabel *placeHoldeLabel;
@property (nonatomic, strong) UIImageView *rightImageView;

@end

@implementation BDPayRedEnvelopeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    style = UITableViewCellStyleValue1;
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
    }
    return self;
}

- (void)configeWithModel:(id)model{
    self.textLabel.text = model[@"title"];
    if ([model[@"subTitle"] isNotEmpty]) {
        self.rightImageView.hidden = YES;
        self.placeHoldeLabel.hidden = YES;
        self.detailTextLabel.hidden = NO;
        self.detailTextLabel.text = model[@"subTitle"];
    }else{
        self.placeHoldeLabel.text = model[@"placeholdTitle"];
        self.placeHoldeLabel.hidden = NO;
        self.detailTextLabel.hidden = YES;
        self.rightImageView.hidden = NO;
    }
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.textLabel.font = [UIFont systemFontOfSize:15];
    self.textLabel.textColor = [UIColor colorWithHexString:@"#1c1c1c"];
    [self.textLabel sizeToFit];
    self.textLabel.left = 10;
    self.textLabel.centerY = self.height / 2.0;
    
    self.placeHoldeLabel.font = [UIFont systemFontOfSize:10];
    self.placeHoldeLabel.textColor = [UIColor whiteColor];
    self.placeHoldeLabel.backgroundColor = [UIColor orangeColor];
    self.placeHoldeLabel.textAlignment = NSTextAlignmentCenter;
    self.placeHoldeLabel.layer.masksToBounds = YES;
    self.placeHoldeLabel.layer.cornerRadius = 3;
    [self.placeHoldeLabel sizeToFit];
    self.placeHoldeLabel.width += 10;
    self.placeHoldeLabel.height += 10;
    self.placeHoldeLabel.right = self.width - 30;
    self.placeHoldeLabel.centerY = self.height / 2.0;
    
    self.detailTextLabel.font = [UIFont systemFontOfSize:13];
    self.detailTextLabel.textColor = [UIColor colorWithHexString:@"#ff4f00"];
    [self.detailTextLabel sizeToFit];
    self.detailTextLabel.right = self.width - 10;
    self.detailTextLabel.centerY = self.height / 2.0;
    
    self.rightImageView.size = CGSizeMake(15, 15);
    self.rightImageView.right = self.width - 8;
    self.rightImageView.centerY = self.height / 2.0;
    self.rightImageView.image = [UIImage imageNamed:@"righ"];
}

- (UILabel *)placeHoldeLabel{
    if (!_placeHoldeLabel) {
        self.placeHoldeLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_placeHoldeLabel];
    }
    return _placeHoldeLabel;
}

- (UIImageView *)rightImageView{
    if (!_rightImageView) {
        self.rightImageView = [[UIImageView alloc] init];
        [self addSubview:_rightImageView];
    }
    return _rightImageView;
}

@end
